package com.llxz.blog.article.handler;

import com.llxz.blog.article.util.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by IntelliJ IDEA.
 *
 * @author zzh
 * @description:. date: 2021/9/8 9:36
 */

@RestControllerAdvice(basePackages = "com.blog.article.controller")
public class WebExceptionHandler {
    @ResponseBody
    @ExceptionHandler(value = NullPointerException.class)
    public JsonResult GlobalException(HttpServletRequest httpServletRequest, NullPointerException e) {
        e.printStackTrace();
        return new JsonResult(2001, "error");
    }

    @ExceptionHandler(value =Exception.class)
    @ResponseBody
    public JsonResult exceptionHandler(HttpServletRequest req, Exception e){
        e.printStackTrace();
        return new JsonResult(2001, "error");
    }
}
